define(function(require, exports){
	var $       = require("jquery");
	var util    = require('util');
	var pubjs   = require('pubjs');
	var view    = require('@base/view');
	var utilDSP = require('modules/common');

	var Main = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'P-advertiserListInfo',
				'url_info': 'qualification/info',
				'grid_config': null, // 列表配置
				'gridName': 'customer',
				'vModel':{
					'Name': '',
					'Id': '',
					'showHead': false,
					'status':[0,0,0]
				},
				'vMethods':{
					'toUrl': this.toUrl,
					'showAptitude': this.showAptitude,
					'showStatus': this.showStatus
				},
				'materials':[
					// {Name:"营业执照",Thumb:"/api/dsp/thumb/certificate?id=234_0&c=-dxyufa",CrtBeginDate:2017-6,CrtEndDate:2018-1,CrtId:'sss1wd',TypeId:'1024'},
					// {Name:"增值电信业务经营许可证",Thumb:"/api/dsp/thumb/certificate?id=234_0&c=-dxyufa",Tanxurl:'http://fanyi.baidu.com/?aldtype=23#en/zh/Crt',CrtBeginDate:2017-6,CrtEndDate:2018-1,CrtId:'sss1wd',TypeId:'1027'},
					// {Name:"扩展资源文件",Thumb:"/api/dsp/thumb/certificate?id=233_2&c=-r4bfii",CrtBeginDate:2017-6,CrtEndDate:2018-1,CrtId:'sss1wd',TypeId:'1106'}
				],
				'status':[
					// {BrandName:"",ExchangeId:10013,Industry:"null",IsDeleted:false,Process:1,Status:0},
					// {BrandName:"",ExchangeId:10013,Industry:"null",IsDeleted:false,Process:1,Status:1},
					// {BrandName:"",ExchangeId:10013,Industry:"null",IsDeleted:false,Process:1,Status:-1},
				]
			});
			this.Super('init', arguments);
		},
		afterBuild:function(){
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM();

			self.append($([
				'<div class="M-formHead P-advertiserListInfoHead" v-show="showHead">',
					'<span class="name" v-on:click="toUrl" pub>{{ Name }}<i class="uk-icon-pencil ml10" ms-click="toUrl"/></span>',
					'<ul class="detail">',
						'<li>',
							'<div>' + LANG('ID') + '</div>',
							'<div>{{ Id }}</div>',
						'</li>',
						'<li>',
							'<div>' + LANG('公司资质') + '</div>',
							'<span class="link" v-on:click="showAptitude">' + LANG('查看资质') + '</span>',
						'</li>',
						'<li>',
							'<div>' + LANG('渠道审核') + '</div>',
							'<div  style="cursor:pointer" v-on:click="showStatus"> 通过 ({{status[0]}}) 审核中 ({{status[1]}}) 拒绝 ({{status[2]}})</div>',
						'</li>',
					'</ul>',

				'</div>',
			].join('')));

			this.vm.mount();

			var config = {

			};

			self.buildFromTemplate(config);
		},
		toUrl: function(){
			//编辑广告主
			var c = this.getConfig();
			if(c.vModel.Id){
				window.open("#serving/advertiserEdit/"+c.vModel.Id);
			}
		},
		showAptitude: function(){
		 	var self = this;
            //查看资质 弹窗
            var mod = self.get('popAptitude');
            var c = self.getConfig();
            if(!mod){
                self.createAsync('popAptitude', 'advertiser/popwin/popwin.popAptitude', {}, function(module){
                    if(module){
                        module.setData(c.materials).show();
                    }
                });
            }else{
                mod.setData(c.materials).show();
            }
		},
		showStatus: function(){
			var self = this;
            //查看 弹窗
            var mod = self.get('popStatus');
            var c = self.getConfig();
            if(!mod){
                self.createAsync('popStatus', 'advertiser/popwin/popwin.popStatus', {}, function(module){
                    if(module){
                        module.setData(c.status).show();
                    }
                });
            }else{
                mod.setData(c.status).show();
            }
		},
		load: function(id){
			var self = this;
			var c = self.getConfig();
			pubjs.mc.send(c.url_info, {'_id': id}, self.onData.bind(self));
			return self;
		},
		onData: function(err, data) {
			if (err) {
				pubjs.error(err.message);
				pubjs.alert(err.message);
				return false;
			}
			var c = this.getConfig();
			this.vm.$.Name = data.UserName;
			this.vm.$.Id = data._id;
			this.vm.$.showHead = true;
			this.totalStatus(data.Info);
			c.materials = data.Materials;
			c.status = data.Info;
		},
		reset: function(){
			this.vm.reset();
			return this;
		}
		,totalStatus:function(info){
			var self = this;
			var temp = [0,0,0];
			util.each(info,function(item,idx){
				switch(item.Status){
					case 1:
						temp[0]++;break;
					case 0:
						temp[1]++;break;
					case -1:
						temp[2]++;break;
				}
			})
			self.vm.$.status = temp;
		}
	});
	exports.main = Main;
});